<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('项目市值变动') }}</span>
    </div>
    <el-row>
      <el-col v-loading="loading" :span="24" height="50%">
        <Empty :data="chartData.datas">
          <lineChart v-if="chartData.datas.length > 0" height="300px" :chart-data="chartData" />
        </Empty>
      </el-col>
      <el-col v-loading="loading" :span="24">
        <el-table v-loading="loading" :data="dealSpoClosePriceList" border tooltip-effect="darkTable">
          <el-table-column :label="$t('交易日期')" align="center" prop="createTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.closingDate) }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t('最新市值')" align="center" prop="latestValue">
            <template slot-scope="scope">
              <span>{{ moneyFormat(scope.row.latestValue) }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t('市值变动')" align="center" prop="valueChange" />
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
    <!-- 添加或修改定增项目-收盘价明细对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealSpoClosePriceForm ref="dealSpoClosePriceForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listDealSpoClosePrice, delDealSpoClosePrice, exportDealSpoClosePrice, getChart } from '@/api/deal/spo/closePrice/dealSpoClosePrice'
import dealSpoClosePriceForm from './dealSpoClosePriceForm.vue'
import lineChart from '@/views/chart/lineChart.vue'
export default {
    components: {
        dealSpoClosePriceForm, lineChart
    },
  data() {
      return {
        // 统计
          chartData: {
            datas: []
          },
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 定增项目-收盘价明细表格数据
          dealSpoClosePriceList: [],
          // 弹出层标题
          title: '定增项目-收盘价明细',
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
              dealId: this.$route.query.id,
              securityName: undefined,
              securityCode: undefined,
              closePrice: undefined,
              chg: undefined,
              yield: undefined,
              revenueAmount: undefined,
              latestValue: undefined,
              valueChange: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getChartList()
      this.getList()
  },
  methods: {
    /** 查询定增项目-项目市值图 */
    getChartList() {
      this.chartLoading = true
      getChart(this.queryParams).then(response => {
        // 无分页
        this.chartLoading = false
        this.chartData = {
          legend: true,
          datas: [],
          legendLeft: 'center',
          xLabel: []
        }
        if (response.data != null) {
          this.chartData.xLabel = response.data.x
          this.chartData.datas = [
              {
              name: this.$t('市值'),
              data: response.data.y
            }
          ]
        }
      })
    },
    /** 查询定增项目-收盘价明细列表 */
    getList() {
        this.loading = true
        listDealSpoClosePrice(this.queryParams).then(response => {
            this.dealSpoClosePriceList = response.rows
            this.total = response.total
            this.loading = false
        }).catch(() => {
            this.loading = false
        })
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            dealId: undefined,
            securityName: undefined,
            securityCode: undefined,
            closePrice: undefined,
            chg: undefined,
            yield: undefined,
            revenueAmount: undefined,
            latestValue: undefined,
            valueChange: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.dealSpoClosePriceForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.dealSpoClosePriceForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return delDealSpoClosePrice(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(() => {
            this.loading = false
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return exportDealSpoClosePrice(queryParams)
        }).then(response => {
            this.download(response.msg)
        }).catch(() => {
        })
    }
  }
}
</script>
